from tw.api import WidgetsList,CSSLink,js_callback
from tw.forms import TableForm
from tw.forms.fields import TextField, RadioButton,RadioButtonList
from tg import url
from tw.jquery.autocomplete import AutoCompleteField
from tw.forms.validators import Int, NotEmpty,UnicodeString,All,ForEach,DateConverter
from tw.rating import Rating
from custom_validators import UniqueParty
from formencode import Schema,validators

party_name = TextField(id='party_name',label_text=u'Party Name',help_text=u'Enter the party name here. This should be the full official party name (e.g. International Business Machines, not IBM)',)
                #validator=All(NotEmpty(messages={'empty':'Party name cannot be empty'}),UniqueParty()))

party_nick = TextField(id="party_nick",label_text=u'Party Nickname', help_text=u'Enter a nickname, if desired (e.g. IBM instead of International Business Machines)')

parent_autocomplete = AutoCompleteField(
                   id='parent_autocomplete',
                   label_text=u"Parent Name",
                   help_text=u"If the party you wish to add has a parent party which already exists in the database, start typing the parent party's name here",
                   completionURL = '/party/fetch_parties',
                   fetchJSON = True,
                   minChars = 2)

#risk = RadioButtonList(id='risk',name='risk',template="lifepyscle.widgets.templates.rbl",label_text=u"Party Risk", help_text=u"Associate a risk with dealing with this party",
#                     options = [('1',u'Very Low',{'class':'star1','name':'star'}),\
#                                ('2',u'Low',{'class':'star1','name':'star'}),\
#                                ('3',u'Medium',{'class':'star1','name':'star'}),\
#                                ('4',u'High',{'class':'star1','name':'star'}),\
#                                ('5',u'Very High',{'class':'star1','name':'star'})] )
from tw.forms import TableForm

parties_autocomplete_form = TableForm(
    template = "lifepyscle.widgets.templates.table_form",
    hover_help = True,
    submit_text = "Add Party",
    id='parties_autocomplete_form',
    children=[party_name,party_nick,parent_autocomplete],action=url('/party/do_add'))

